<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
var generate = function(numRows) {
    if(numRows == 0){
        return []
    }
    else if(numRows == 1){
        return [[1]]
    }
    else if(numRows == 2){
        return [[1],[1,1]]
    }
    var arr = [[1],[1,1]]
    var temp
    for( var i = 2 ; i<numRows ; i++ ){
        var xxx = [1,1]
        for( var k = 1 ; xxx.length<i+1 ; k++ ){
            temp = arr[i-1][k-1] + arr[i-1][k]
            xxx.splice(k,0,temp)
        }
        arr.push(xxx)
    }
    return arr
};

var numRows = 5
console.log(generate(numRows))
    </script>
</body>
</html>